#! /usr/bin/env python
from waf_dynamo import apidoc_extract_task
import waflib.Options

def configure(conf):
    pass

def build(bld):
    embed_source = ''

    source = 'profiler.cpp profiler_render.cpp basic/profiler_basic.cpp'
    source_null = 'profiler_null.cpp'

    if 'macos' in bld.env.PLATFORM or 'ios' in bld.env.PLATFORM:
        source += ' profiler_cocoa.mm'
    elif 'android' in bld.env.PLATFORM:
        source += ' profiler_android.cpp'
        source += ' profiler_proc_utils.cpp'
    elif 'linux' in bld.env.PLATFORM:
        source += ' profiler_linux.cpp'
        source += ' profiler_proc_utils.cpp'
    elif 'win32' in bld.env.PLATFORM:
        source += ' profiler_win32.cpp'
    elif bld.env['PLATFORM'] in ('js-web', 'wasm-web', 'wasm_pthread-web'):
        source += ' profiler_web.cpp'
    else:
        source += ' profiler_unsupported.cpp'

    profiler = bld.stlib(features = 'cxx',
                            includes = '.',
                            source = source,
                            target = 'profilerext')

    profiler = bld.stlib(features = 'cxx',
                            includes = '.',
                            source = source_null,
                            target = 'profilerext_null')

    if bld.env['PLATFORM'] not in ('js-web', 'wasm-web', 'wasm_pthread-web', 'arm64-nx64', 'x86_64-ps4', 'x86_64-ps5'):
        profiler = bld.stlib(features = 'c cxx',
                                includes = '.',
                                source = 'remotery/profiler_remotery.cpp remotery/lib/Remotery.c',
                                target = 'profiler_remotery')

    if bld.env['PLATFORM'] in ('js-web', 'wasm-web', 'wasm_pthread-web'):
        profiler = bld.stlib(features = 'cxx',
                                includes = '.',
                                source = 'js/profiler_js.cpp',
                                target = 'profiler_js')


    bld.install_files('${PREFIX}/include/profiler', 'profiler.h')
    if 'web' in bld.env['PLATFORM']:
        bld.install_files('${PREFIX}/lib/%s/js' % bld.env['PLATFORM'], 'js/library_profile.js')

    apidoc_extract_task(bld, ['profiler.cpp'])

    if not waflib.Options.options.skip_build_tests:
        bld.recurse('test')

